/* uDig - User Friendly Desktop Internet GIS client
 * http://udig.refractions.net
 * (C) 2004-2008, Refractions Research Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package symbology;

/**
 * Represents a color (RGB + optional Opacity)
 * <p>
 *
 * </p>
 * @author John Morris
 * @since 1.1.0
 */
final public class Color {
   
    static public final Color NONE = new Color(0,0,0,0);
    static public final Color RED = new Color(255,0,0);
    static public final Color GREEN = new Color(0, 255, 0);
    static public final Color BLUE = new Color(0, 0, 255);
    static public final Color BLACK = new Color(0, 0, 0);
    static public final Color WHITE = new Color(255, 255, 255);
    
    private final int encoding;
    
    public Color(int R, int G, int B, double Opacity)
    {
        encoding = (R<<24) + (G<<16) + (B<<8) + (int)(Opacity*255);
    }
    
    public Color(int R, int G, int B)
    {
        this(R, G, B, 1.0);
    }
    
    public Color(Color color, double opacity)
    {
        this(color.getR(), color.getG(), color.getB(), opacity);
    }
    
    public int getR()
    {
        return (encoding >>> 24);
    }
    
    public int getG()
    {
        return ((encoding >>> 16) & 255);
    }
    
    public int getB()
    {
        return  ((encoding >>> 8) & 255);
    }
    
    public double getOpacity()
    {
        return (encoding & 255) / 255.0 ;
    }
}
